package com.sgb.kjwl.view.widget;

import android.content.Context;
import android.text.InputType;
import android.text.TextUtils;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.sgb.goods.entity.GoodsSkuSelectResultEntity;
import com.sgb.kjwl.R;
import com.sgb.kjwl.api.APIManager;
import com.sgb.kjwl.api.NewAPIManager;
import com.sgb.kjwl.model.entity.GoodsSkuDetailEntity;
import com.sgb.kjwl.model.entity.SkuCheckEntity;
import com.sgb.kjwl.model.entity.SkuCombinationEntity;
import com.sgb.kjwl.model.entity.user.SkuInfoEntity;
import com.sgb.kjwl.pop.InputPop;
import com.sgb.kjwl.utils.NumberFormatUtils;
import com.swgk.core.util.UiUtil;
import com.swgk.core.event.EventConstant;
import com.sgb.kjwl.view.ui.activity.self.shop.ShopGoodsDetailActivity;
import com.sgb.kjwl.view.ui.adapter.material.GoodsSkuCheckAdapter;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.dialog.BasePopWindow;
import com.swgk.core.dialog.DialogHelper;
import com.swgk.core.dialog.PopViewHolder;
import com.swgk.core.util.MLog;
import com.swgk.core.util.MToast;
import com.swgk.core.util.ScreenUtil;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import razerdp.basepopup.BasePopupWindow;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class GoodSSkuWindow extends BasePopWindow {
    private RecyclerView paramsList;
    private TextView tv_close;
    private TextView tv_price;
    private TextView tv_all_price;
    private TextView tv_cx_time;//促销时间
    private TextView name;
    private LinearLayout actLayout;
    private TextView TvMoney;//原价
    private TextView TvPromotePrice;//促销
    private TextView TvVipPrice;//会员
    private GoodsSkuCheckAdapter goodsParamsAdapter;
    private LinearLayoutManager linearLayoutManager;
    private GoodsSkuDetailEntity data;
    private BigDecimal allBigDecimal;
    private BigDecimal unitPrice;
    private BigDecimal number;
    private String chooseAtr = "";
    private String skuId;
    private ImageView mIvImg, icon_huiyuan;
    private TextView mTvSelect;
    private TextView mTvBuyNumber;
    private View mFlMinus;
    private View mFlAdd;
    private EditText mEtHide;
    private String Money, proMoney, vipMoney, unit, selectSku, promoteStart, promoteEnd, superPrice = "0.00";
    int Type = 0;
    int actType = 0;
    int promoteStatus = 0;
    int checkPosition = 0;

    public GoodSSkuWindow(Context context) {
        super(context, DIR_DOWN_UP);
    }

    @Override
    protected int popLayout() {
        return R.layout.pop_goods_sku;
    }

    @Override
    protected void initView(PopViewHolder holder) {
        paramsList = holder.getPop().findViewById(R.id.params_list);
        tv_close = holder.getPop().findViewById(R.id.tv_close);
        tv_price = holder.getPop().findViewById(R.id.tv_price);
        tv_cx_time = holder.getPop().findViewById(R.id.tv_cx_time);
        actLayout = holder.getPop().findViewById(R.id.act_layout);
        TvMoney = holder.getPop().findViewById(R.id.tv_money);
        TvPromotePrice = holder.getPop().findViewById(R.id.tv_promote_price);
        TvVipPrice = holder.getPop().findViewById(R.id.tv_vip_price);
        tv_all_price = holder.getPop().findViewById(R.id.tv_total_price);
        name = holder.getPop().findViewById(R.id.name);
        mIvImg = holder.getPop().findViewById(R.id.iv_img);
        icon_huiyuan = holder.getPop().findViewById(R.id.icon_huiyuan);
        mTvSelect = holder.getPop().findViewById(R.id.tv_select);
        mTvBuyNumber = holder.getPop().findViewById(R.id.tv_buy_number);
        mFlMinus = holder.getPop().findViewById(R.id.fl_minus);
        mEtHide = holder.getPop().findViewById(R.id.et_hide);
        mFlAdd = holder.getPop().findViewById(R.id.fl_add);
        holder.getPop().findViewById(R.id.view_goods_sku_close).setOnClickListener(v -> dismiss());
        // 弹框
        TvMoney.setOnClickListener(v -> setTv_price(1, actType, Money, proMoney, vipMoney));
        TvPromotePrice.setOnClickListener(v -> setTv_price(2, actType, Money, proMoney, vipMoney));
        TvVipPrice.setOnClickListener(v -> setTv_price(3, actType, Money, proMoney, vipMoney));

        mTvBuyNumber.setOnClickListener(v -> {
            InputPop inputPop = new InputPop(mContext);
            if (!data.getUnit().contains("米") && !data.getUnit().contains("升") && !data.getUnit().contains("吨") && !data.getUnit().contains("千克")) {
                inputPop.mEtInputNumber.setInputType(InputType.TYPE_CLASS_NUMBER);
            }
            inputPop.mEtInputNumber.setText(UiUtil.rvZeroAndDot(mTvBuyNumber.getText().toString()));
            inputPop.mTvSure.setOnClickListener(v1 -> {
                if (!TextUtils.isEmpty(inputPop.mEtInputNumber.getText().toString())) {
                    double num = Double.parseDouble(inputPop.mEtInputNumber.getText().toString());
                    {
                        if (num < data.lowestBuy) {
                            MToast.showToast(UiUtil.getContext(), "温馨提示：该商品不能减少了哟~");
                        } else if (num > 999999.999) {
                            MToast.showToast(UiUtil.getContext(), "温馨提示：该商品不能添加了哟~");
                        } else {
                            InputMethodManager imm = (InputMethodManager) UiUtil.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
                            imm.hideSoftInputFromWindow(inputPop.mEtInputNumber.getWindowToken(), 0);
                            mTvBuyNumber.setText(UiUtil.rvZeroAndDot(String.valueOf(Double.parseDouble(inputPop.mEtInputNumber.getText().toString()))));
                            number = new BigDecimal(mTvBuyNumber.getText() + "");
                            allBigDecimal = unitPrice.multiply(number);
                            tv_all_price.setText("¥" + NumberFormatUtils.formatAmt(Float.valueOf(allBigDecimal.toString())));
                            inputPop.dismiss();
                        }
                    }
                } else {
                    inputPop.dismiss();
                }
            });
            inputPop.setOnDismissListener(new BasePopupWindow.OnDismissListener() {
                @Override
                public void onDismiss() {
                    // TODO: 2020/12/14 0014
                    InputMethodManager imm = (InputMethodManager) UiUtil.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
                    imm.hideSoftInputFromWindow(mEtHide.getWindowToken(), 0);
                }
            });
            inputPop.showPopupWindow();

        });
        // 加
        mFlAdd.setOnClickListener(
                v -> {
                    double num = Double.parseDouble(mTvBuyNumber.getText().toString());
                    num++;
                    if (num > 999999.999) {
                        MToast.showToast(UiUtil.getContext(), "温馨提示：该商品不能添加了哟~");
                        holder.getPop().findViewById(R.id.fl_add).setBackgroundResource(R.drawable.corner2_right_radius_false);
                        return;
                    }
                    holder.getPop().findViewById(R.id.fl_minus).setBackgroundResource(R.drawable.corner2_left_radius);
                    mTvBuyNumber.setText(UiUtil.rvZeroAndDot(String.valueOf(num)));

                    number = new BigDecimal(mTvBuyNumber.getText() + "");
                    if (unitPrice == null) {
                        String price = "";
                        if (data.getPriceScope().contains("~")) {
                            price = data.getPriceScope().split("~")[0];
                        } else {
                            price = data.getPriceScope();
                        }
                        unitPrice = new BigDecimal(price);
                    }
                    allBigDecimal = unitPrice.multiply(number);
                    tv_all_price.setText("¥" + NumberFormatUtils.formatAmt(Float.valueOf(allBigDecimal.toString())));
                }
        );

        // 减
        mFlMinus.setOnClickListener(v -> {
            double num = Double.parseDouble(mTvBuyNumber.getText().toString());
            if (num > data.lowestBuy) {
                num--;
                mTvBuyNumber.setText(UiUtil.rvZeroAndDot(String.valueOf(num)));
                holder.getPop().findViewById(R.id.fl_add).setBackgroundResource(R.drawable.corner2_right_radius);
                if (num < data.lowestBuy) {
                    holder.getPop().findViewById(R.id.fl_minus).setBackgroundResource(R.drawable.corner2_left_radius_false);
                }
                number = new BigDecimal(mTvBuyNumber.getText() + "");
                allBigDecimal = unitPrice.multiply(number);
                tv_all_price.setText("¥" + NumberFormatUtils.formatAmt(Float.valueOf(allBigDecimal.toString())));
            } else {
                MToast.showToast(UiUtil.getContext(), "温馨提示：该商品不能减少了哟~");
            }
        });

        if (goodsParamsAdapter == null) {
            goodsParamsAdapter = new GoodsSkuCheckAdapter(mContext, null);
        }
        goodsParamsAdapter.OnPrice(new GoodsSkuCheckAdapter.IPrice() {
            @Override
            public void getMoney(String money) {
                if (data.isSku()) {
                    try {
                        System.out.println("1111111111111111===" + money);
                        tv_price.setText("¥" + NumberFormatUtils.formatAmt(Float.valueOf(superPrice)) + "/" + data.getUnit());
                        unitPrice = new BigDecimal(superPrice);
                        number = new BigDecimal(mTvBuyNumber.getText() + "");
                        allBigDecimal = unitPrice.multiply(number);
                        tv_all_price.setText("¥" + NumberFormatUtils.formatAmt(Float.valueOf(allBigDecimal.toString())));

                        if (data.getItemAttr() != null) {
                            List<SkuCheckEntity> list = data.getItemAttr().getCheck();
                            StringBuffer sb = new StringBuffer();
                            if (list != null) {
                                for (int i = 0; i < list.size(); i++) {
                                    sb.append(list.get(i).getVal() + " ");
                                }
                            }
                        }
                    } catch (Exception e) {
                        Toast.makeText(mContext, "数据异常", Toast.LENGTH_SHORT).show();
                    }
                }
            }

            @Override
            public void getMoney1(SkuCombinationEntity skuCombinationEntity, int type, int position) {
                if (data.getItemAttr() != null) {
                    List<SkuCheckEntity> list = data.getItemAttr().getCheck();
                    StringBuffer sb = new StringBuffer();
                    if (list != null) {
                        for (int i = 0; i < list.size(); i++) {
                            sb.append(list.get(i).getVal() + "\t");
                        }
                        mTvSelect.setText("已选择:\t" + sb.toString());
                        selectSku = sb.toString();
                    }
                }
                Money = skuCombinationEntity.getMoney();
                proMoney = skuCombinationEntity.getPromotePrice();
                vipMoney = skuCombinationEntity.getVipPrice();
                unit = data.getUnit();
                promoteStart = skuCombinationEntity.getPromoteStartTime();
                promoteEnd = skuCombinationEntity.getPromoteEndTime();
                promoteStatus = skuCombinationEntity.getPromoteStatus();
                checkPosition = position;
                if (type == 1) {
                    if (data.isSku()) {
                        try {
                            skuId = skuCombinationEntity.getId();
//                            paramsList.scrollBy(0,1);
                            getSuperPrice(vipMoney, proMoney, Money, promoteStatus);
                        } catch (Exception e) {
                            Toast.makeText(mContext, "数据异常", Toast.LENGTH_SHORT).show();
                        }
                    }
                } else {
                    HashMap map = new HashMap();
                    HashMap map1 = new HashMap();
                    map.put("itemId", ((ShopGoodsDetailActivity) mContext).shopId);
                    if (data.getItemAttr() != null) {
                        List<SkuCheckEntity> list = data.getItemAttr().getCheck();
                        StringBuffer sb = new StringBuffer();
                        if (list != null) {
                            for (int i = 0; i < list.size(); i++) {
                                map1.put(list.get(i).getId(), list.get(i).getValId());
                                sb.append(list.get(i).getVal() + " ");
                            }
                        }
                    }
                    map.put("attribute", map1);
                    getSuperPrice(vipMoney, proMoney, Money, promoteStatus);
                    getGoodsAttributeEnabled(map);
                }
            }
        });
        linearLayoutManager = new LinearLayoutManager(mContext);
        paramsList.setLayoutManager(linearLayoutManager);
        paramsList.setAdapter(goodsParamsAdapter);
        // TODO: 2020/12/11 0011
        tv_close.setOnClickListener(v -> {
            dismiss();
            if (data.getItemAttr() != null && data.getItemAttr().getCheck().size() != 0 && data.getItemAttr().getSku().size() != 0) {
                List<SkuCheckEntity> list = data.getItemAttr().getCheck();
                StringBuffer sb = new StringBuffer();
                if (list != null) {
                    for (int i = 0; i < list.size(); i++) {
                        sb.append(list.get(i).getVal() + " ");
                    }
                }
                chooseAtr = sb.toString();
            } else {
                chooseAtr = data.getCartTitle();
            }
            if (onResultClick != null) {
                if (data.getItemAttr() != null && data.getItemAttr().getCheck() != null && data.getItemAttr().getCheck().size() == 0) {
                    Money = data.getCheckedItemAttr().getList().get(0).getMoney();
                    proMoney = data.getCheckedItemAttr().getList().get(0).getPromotePrice();
                    vipMoney = data.getCheckedItemAttr().getList().get(0).getVipPrice();
                    unit = data.getUnit();
                }
                GoodsSkuSelectResultEntity resultEntity = new GoodsSkuSelectResultEntity(Money, proMoney, vipMoney, promoteStart, promoteEnd, Type, promoteStatus, checkPosition, unit);
                onResultClick.result(mTvBuyNumber.getText().toString(), chooseAtr, resultEntity);
                if (!TextUtils.isEmpty(selectSku)) {
                    UiUtil.sendMsg(EventConstant.EVENT_SELECT, selectSku);
                }
            }
        });

    }

    public void setData(GoodsSkuDetailEntity data, String s) {
        if (data == null) {
            return;
        }
        this.data = data;
        this.superPrice = s;
        if (data.getImages() != null && data.getImages().size() > 0) {
            Glide.with(mContext).load(data.getImages().get(0)).apply(new RequestOptions().centerCrop()).into(mIvImg);
        }
        if (data.lowestBuy == 0) {
            data.lowestBuy = 1;
        }
        mTvBuyNumber.setText(UiUtil.rvZeroAndDot(String.valueOf(data.lowestBuy)));
        mFlMinus.setBackgroundResource(R.drawable.corner2_left_radius_false);
        if (data.isSku()) {
            paramsList.setVisibility(View.VISIBLE);
            if (data.getItemAttr() != null && data.getItemAttr().getCheck().size() != 0 && data.getItemAttr().getSku().size() != 0) {
                goodsParamsAdapter.setDatas(data.getItemAttr().getSku());
                goodsParamsAdapter.setCheckData(data.getItemAttr().getCheck(), data.getCheckedItemAttr().getList());
            } else {
                SkuCombinationEntity entity = data.getCheckedItemAttr().getList().get(0);
                Money = entity.getMoney();
                proMoney = entity.getPromotePrice();
                vipMoney = entity.getVipPrice();
                unit = data.getUnit();
                promoteStart = entity.getPromoteStartTime();
                promoteEnd = entity.getPromoteEndTime();
                promoteStatus = entity.getPromoteStatus();
                checkPosition = 0;
                getSuperPrice(entity.getVipPrice(), entity.getPromotePrice(), entity.getMoney(), entity.getPromoteStatus());
                paramsList.setVisibility(View.GONE);
            }
        } else {
            tv_price.setText("¥" + NumberFormatUtils.formatAmt(Float.valueOf(data.getPrice())) + "/" + data.getUnit());
            tv_all_price.setText("¥" + NumberFormatUtils.formatAmt(Float.valueOf(data.getPrice())));
            unitPrice = new BigDecimal(data.getPrice());
            paramsList.setVisibility(View.GONE);
        }
        name.setText(data.getCartTitle());
    }

    public void getGoodsAttributeEnabled(Map map) {
        DialogHelper.showProgressDialog2(mContext, null, "数据加载中...", 0, false, null, false);
        NewAPIManager.getInstance().getGoodsAPI().getGoodsAttributeEnabled(map).enqueue(new Callback<BaseEntity<SkuInfoEntity>>() {
            @Override
            public void onResponse(Call<BaseEntity<SkuInfoEntity>> call, Response<BaseEntity<SkuInfoEntity>> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body().getState() != null && response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    ShopGoodsDetailActivity.skuId = response.body().getData().getSkuId();
                    for (int i = 0; i < data.getItemAttr().getSku().size(); i++) {
                        for (int j = 0; j < data.getItemAttr().getSku().get(i).getList().size(); j++) {
                            goodsParamsAdapter.getDatas().get(i).getList().get(j).setEnabled(response.body().getData().getList().get(i).getList().get(j).isEnabled());
                        }
                    }
                    goodsParamsAdapter.notifyDataSetChanged();
                } else {
                    MToast.showToast(mContext, response.body().getMsg());
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<SkuInfoEntity>> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });
    }

    /**
     * @param vipPrice     会员价
     * @param promotePrice 促销价
     * @param money        原价
     * @param status       促销状态
     */
    public void getSuperPrice(String vipPrice, String promotePrice, String money, int status) {
        promoteStatus = status;
        long nowTime = System.currentTimeMillis();
        long startTime1 = Long.parseLong(TextUtils.isEmpty(promoteStart) ? "0" : promoteStart) - nowTime;
        long endTime1 = Long.parseLong(TextUtils.isEmpty(promoteEnd) ? "0" : promoteEnd);
        boolean isStartTime = startTime1 / 86400000 >= 3;
        boolean isEndTime = endTime1 > nowTime;
        if (!TextUtils.isEmpty(vipPrice) && Double.parseDouble(vipPrice) > 0) {
            //既有会员价又有促销价
            if (status == 1) {
                if (isStartTime) {//大于三天不展示促销价
                    Type = 3;
                    actType = 2;
                } else {
                    if (Double.parseDouble(promotePrice) < Double.parseDouble(vipPrice)) {
                        Type = 2;
                        actType = 3;
                    } else {
                        Type = 3;
                        actType = 3;
                    }
                }
            } else if (status == 2 && isEndTime) {
                if (Double.parseDouble(promotePrice) < Double.parseDouble(vipPrice)) {
                    Type = 2;
                    actType = 3;
                } else {
                    Type = 3;
                    actType = 3;
                }
            } else {//只有会员价
                Type = 3;
                actType = 2;
            }
        } else {
            //只有促销价
            if (status == 1) {
                if (isStartTime) {
                    Type = 1;
                    actType = 0;
                } else {
                    Type = 2;
                    actType = 1;
                }
            } else if (status == 2 && isEndTime) {
                Type = 2;
                actType = 1;
            } else {//原价
                Type = 1;
                actType = 0;
            }
        }
        setTv_price(Type, actType, money, promotePrice, vipPrice);
    }

    /**
     * 设置显示价格
     *
     * @param SelectType   选中的价格项类型 1 原价 2 促销价 3 会员价
     * @param actType      活动需要显示的价格类型 1 原价&促销价 2 原价&会员价 3 三个价格都有
     * @param money        原价
     * @param promotePrice 促销价
     * @param vipMoney     会员价
     */
    private void setTv_price(int SelectType, int actType, String money, String promotePrice, String vipMoney) {
        Type = SelectType;
        if (SelectType == 1) {
            unitPrice = new BigDecimal(money);
        } else if (SelectType == 2) {
            unitPrice = new BigDecimal(promotePrice);
        } else {
            unitPrice = new BigDecimal(vipMoney);
        }
        number = new BigDecimal(mTvBuyNumber.getText() + "");
        allBigDecimal = unitPrice.multiply(number);
        String totalPrice = "¥" + NumberFormatUtils.formatAmt(Float.valueOf(allBigDecimal.toString()));
        MLog.e("&&&&&&&&" + totalPrice);
        if (allBigDecimal != null) {
            tv_all_price.setText(totalPrice);
        }
        tv_price.setText("¥" + NumberFormatUtils.formatAmt(Float.valueOf(SelectType == 1 ? money : SelectType == 2 ? promotePrice : vipMoney)) + "/" + data.getUnit());
        //只有促销价
        if (actType == 1) {
            actLayout.setVisibility(View.VISIBLE);
            TvVipPrice.setVisibility(View.INVISIBLE);
            TvMoney.setBackgroundResource(SelectType == 1 ? R.drawable.corner2_105792fd_bg : R.drawable.corner2_f5f5f5_bg);
            TvMoney.setTextColor(SelectType == 1 ? mContext.getResources().getColor(R.color.color_main) : mContext.getResources().getColor(R.color.color_666666));
            TvPromotePrice.setBackgroundResource(SelectType == 2 ? R.drawable.corner2_105792fd_bg : R.drawable.corner2_f5f5f5_bg);
            TvPromotePrice.setTextColor(SelectType == 2 ? mContext.getResources().getColor(R.color.color_main) : mContext.getResources().getColor(R.color.color_666666));
        } else if (actType == 2) {
            //只有会员价
            actLayout.setVisibility(View.VISIBLE);
            TvVipPrice.setVisibility(View.VISIBLE);
            TvPromotePrice.setVisibility(View.GONE);
            TvMoney.setBackgroundResource(SelectType == 1 ? R.drawable.corner2_105792fd_bg : R.drawable.corner2_f5f5f5_bg);
            TvMoney.setTextColor(SelectType == 1 ? mContext.getResources().getColor(R.color.color_main) : mContext.getResources().getColor(R.color.color_666666));
            TvVipPrice.setBackgroundResource(SelectType == 3 ? R.drawable.corner2_105792fd_bg : R.drawable.corner2_f5f5f5_bg);
            TvVipPrice.setTextColor(SelectType == 3 ? mContext.getResources().getColor(R.color.color_main) : mContext.getResources().getColor(R.color.color_666666));
        } else if (actType == 3) {
            //促销价和会员价都有
            actLayout.setVisibility(View.VISIBLE);
            TvVipPrice.setVisibility(View.VISIBLE);
            TvPromotePrice.setVisibility(View.VISIBLE);
            TvMoney.setBackgroundResource(SelectType == 1 ? R.drawable.corner2_105792fd_bg : R.drawable.corner2_f5f5f5_bg);
            TvMoney.setTextColor(SelectType == 1 ? mContext.getResources().getColor(R.color.color_main) : mContext.getResources().getColor(R.color.color_666666));
            TvPromotePrice.setBackgroundResource(SelectType == 2 ? R.drawable.corner2_105792fd_bg : R.drawable.corner2_f5f5f5_bg);
            TvPromotePrice.setTextColor(SelectType == 2 ? mContext.getResources().getColor(R.color.color_main) : mContext.getResources().getColor(R.color.color_666666));
            TvVipPrice.setBackgroundResource(SelectType == 3 ? R.drawable.corner2_105792fd_bg : R.drawable.corner2_f5f5f5_bg);
            TvVipPrice.setTextColor(SelectType == 3 ? mContext.getResources().getColor(R.color.color_main) : mContext.getResources().getColor(R.color.color_666666));
        } else {
            actLayout.setVisibility(View.GONE);
        }
        icon_huiyuan.setVisibility(SelectType == 3 ? View.VISIBLE : View.GONE);
        mTvSelect.setVisibility(SelectType == 2 ? View.GONE : View.VISIBLE);
        if (SelectType == 2) {
            if (!TextUtils.isEmpty(promoteStart) && !TextUtils.isEmpty(promoteEnd)) {
                tv_cx_time.setVisibility(View.VISIBLE);
                UiUtil.startPopTimer(Long.parseLong(promoteStart), Long.parseLong(promoteEnd), promoteStatus, tv_cx_time);
            }
        } else {
            tv_cx_time.setVisibility(View.GONE);
        }
    }

    @Override
    public void showDownPopwindow(View view, boolean alpha) {
        int calHeight = null != goodsParamsAdapter && null != goodsParamsAdapter.check && goodsParamsAdapter.check.size() > 0 ?
                (int) (ScreenUtil.getDisplayHeight() * 0.85) : (int) (ScreenUtil.getDisplayHeight() * 0.45);
        setHeight(calHeight);
        super.showDownPopwindow(view, alpha);
    }
}